package com.levi.completableFuture;

import java.util.concurrent.*;

/**
 * @author shentong
 * @since 2022/1/16 4:47 PM
 * thenAcceptAsync()方法用于执行下一个异步任务，任务没有返回值
 */
public class ThenAcceptDemo {
    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(10);
        CompletableFuture<Void> integerCompletableFuture = CompletableFuture.supplyAsync(() -> {
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName());
            return 123;
        }, executorService).thenAcceptAsync(value->{
            System.out.println("thenAcceptAsync"+"-"+value+"-"+Thread.currentThread().getName());
        },executorService);
        System.out.println("Main End~");
//        try {
//            Integer integer = integerCompletableFuture.get();
//            System.out.println(integer);
//        } catch (InterruptedException | ExecutionException e) {
//            e.printStackTrace();
//        }
        executorService.shutdown();
    }
}
